package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.HouseUse;
import com.home.service.HouseUseService;

@Controller
public class HouseUseAction {
	@Autowired
	private HouseUseService houseUseService;

	public HouseUseService getHouseUseService() {
		return houseUseService;
	}

	public void setHouseUseService(HouseUseService houseUseService) {
		this.houseUseService = houseUseService;
	}
	
	@RequestMapping("/admin/houseuse/list.do")
	public String getAll(HttpServletRequest request) {
		List<HouseUse> houseUseList = this.getHouseUseService().getList();
		request.setAttribute("list", houseUseList);
		return "/admin/houseuse/list";
	}

	@RequestMapping("/admin/houseuse/save.do")
	public String getAll(HouseUse houseUse) {
		if (houseUse != null) {
			this.getHouseUseService().save(houseUse);
		}
		Cache.getInstance().refreshHouseUse();
		return "redirect:/admin/houseuse/list.do";
	}

	@RequestMapping("/admin/houseuse/get.do")
	public String getAll(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseUse houseUse = this.getHouseUseService().getHouseUse(id);
			request.setAttribute("obj", houseUse);
		}
		return "/admin/houseuse/obj";
	}
	
	
	@RequestMapping("/admin/houseuse/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseUse houseUse=new HouseUse();
			houseUse.setId(id);
			this.getHouseUseService().delete(houseUse);
		}
		return "redirect:/admin/houseuse/list.do";
	}
	
}
